<template>
	<view class="page">
		<view class="topVue">
			<view class="safeVue" :style="{ height: statusBarHeight + 'rpx' }"></view>
			<view class="flex align-center padding-row30" :style="{ height: barHeight + 'rpx', top: statusBarHeight + 'rpx' }" @click="$tools.back()">
				<image src="../../static/back.png" style="width: 48rpx; height: 48rpx;"></image>
				<text style="line-height: 1; color: #454545; font-weight: 600; font-size: 32rpx; padding-left: 20rpx;">{{ location }}</text>
			</view>
			<view class="tabVue">
				<u-tabs 
					:list="tabs" 
					:current="current" 
					name="classifyName"
					@change="tabChange"
					active-color="#D37430"
				></u-tabs>
			</view>
		</view>

		<view :style="{ height: statusBarHeight + barHeight + 80 + 'rpx' }" style="background: red;"></view>
		
		<view class="listVue">
			<view class="item flex" v-for="(item, index) in list" :key="index" @click="selectFun(item)">
				<image :src="item.url" mode="aspectFill" style="width: 160rpx;"></image>
				<view class="info flex-1">
					<view class="name">{{ item.name }}</view>
					<view class="address">{{ item.location }}</view>
				</view>
			</view>
			<u-empty mode="list" v-if="isEmpty" margin-top="200"></u-empty>
		</view>
		
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		data(){
			return {
				statusBarHeight: 0,
				barHeight: 0,
				tabs:[],
				current: 0,
				categoryId: "",
				list: [],
				isEmpty: false
			}
		},
		async onLoad() {
			let that = this;
			wx.getSystemInfo({
				success(res) {
					let deviceWidth = wx.getSystemInfoSync().windowWidth
					that.statusBarHeight = Number(res.statusBarHeight) * ( 750 / deviceWidth ) 
					let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
					let barHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2
					that.barHeight = Number(barHeight) * ( 750 / deviceWidth )
				},
			});
			await this.getShopCategory()
		},
		computed: {
			...mapState({
				location: state=> state.location,
			})
		},
		methods: {
			tabChange(e){
				console.log(e)
				this.current = e
				this.categoryId = this.tabs[e].id
				this.getList()
			},
			
			// 获取实体店类型
			async getShopCategory(){
				const result = await this.$request("/api/WeChat/shopCategory", {}, "GET")
				if(result.code===200) {
					this.tabs = result.data
					this.categoryId = result.data[0].id
					console.log("获取实体店类型", this.categoryId, this.tabs)	
					this.getList()
				}
			},
			
			async getList(){
				console.log(this.location)
				const result = await this.$request("/api/WeChat/getShopByCategory", {
					storeId: this.categoryId,
					area: this.location
				}, "GET")
				if(result.code===200) {
					this.list = result.data
					this.isEmpty = this.list.length===0
					console.log("获取实体店列表", this.list)	
				}
			},
			
			selectFun(item){
				uni.$emit("storeDetail", item)
				this.$tools.back()
			}
		}
	}
</script>

<style lang="less" scoped>
	.topVue {
		width: 100%;
		background: #fff;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99;
		.safeVue {
			width: 100%;
		}
		.tabVue {
			width: 100%;
			height: 80rpx;
		}
	}
	
	.listVue {
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		.item {
			width: 690rpx;
			height: 160rpx;
			border-radius: 20rpx;
			box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
			margin: 0 auto 30rpx;
			overflow: hidden;
			.info {
				padding: 20rpx;
				.name {
					color: #DFA0A4;
					font-weight: 600;
					line-height: 1;
				}
				.address {
					color: #999;
					line-height: 40rpx;
					padding-top: 15rpx;
				}
			}
		}
	}
	
	
</style>